home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / roids / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  5.7 KB  |  165 lines

  1. /*
  2.  * Copyright 1989 Digital Equipment Corporation
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted,
  6.  * provided that the above copyright notice appear in all copies and that
  7.  * both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of Digital Equipment
  9.  * Corporation not be used in advertising or publicity pertaining to
  10.  * distribution of the software without specific, written prior
  11.  * permission.  Digital Equipment Corporation makes no representations
  12.  * about the suitability of this software for any purpose.  It is
  13.  * provided "as is" without express or implied warranty.
  14.  *
  15.  * DIGITAL EQUIPMENT CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16.  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
  18.  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20.  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21.  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Terry Weissman
  24.  *          weissman@decwrl.dec.com
  25.  */
  26.  
  27. /* main.c -- create our windows and initialize things. */
  28.  
  29. #define MAIN
  30. #include "roids.h"
  31. #include <X11/Xaw/Label.h>
  32. #include <X11/Xaw/Paned.h>
  33.  
  34. static int width, height;        /* Size of window. */
  35. static Pixel defaultfore;    /* Default foreground */
  36. static Pixel defaultback;    /* Default background */
  37. static Pixel scorepixel;    /* Color for score. */
  38.  
  39. static XrmOptionDescRec table[] = {
  40.     {"-debug",    "*debug",    XrmoptionNoArg,    NULL},
  41. };
  42.  
  43. static XtResource resources[] = {
  44.     {XtNwidth, XtCWidth, XtRInt, sizeof(int),
  45.      (Cardinal)&width, XtRImmediate, (caddr_t) 500},
  46.     {XtNheight, XtCHeight, XtRInt, sizeof(int),
  47.      (Cardinal)&height, XtRImmediate, (caddr_t) 400},
  48.     {"debug", "Debug", XtRBoolean, sizeof(Boolean),
  49.      (Cardinal)&debug, XtRString, "off"},
  50.     {"numdir", "NumDir", XtRInt, sizeof(int),
  51.      (Cardinal)&numdir, XtRImmediate, (caddr_t) 48},
  52.     {"shipradius", "ShipRadius", XtRInt, sizeof(int),
  53.      (Cardinal)&shipradius, XtRImmediate, (caddr_t) 12},
  54.     {"shipwait", "ShipWait", XtRInt, sizeof(int),
  55.      (Cardinal)&shipwait, XtRImmediate, (caddr_t) 10},
  56.     {"rockwait", "RockWait", XtRInt, sizeof(int),
  57.      (Cardinal)&rockwait, XtRImmediate, (caddr_t) 30},
  58.     {"shotwait", "ShotWait", XtRInt, sizeof(int),
  59.      (Cardinal)&shotwait, XtRImmediate, (caddr_t) 30},
  60.     {"shipcolor", "ShipColor", XtRPixel, sizeof(Pixel),
  61.      (Cardinal)&shippixel, XtRString, "cyan"},
  62.     {"rockcolor", "RockColor", XtRPixel, sizeof(Pixel),
  63.      (Cardinal)&rockpixel, XtRString, "#fa0"},
  64.     {"shotcolor", "ShotColor", XtRPixel, sizeof(Pixel),
  65.      (Cardinal)&shotpixel, XtRString, "red"},
  66.     {"scorecolor", "ScoreColor", XtRPixel, sizeof(Pixel),
  67.      (Cardinal)&scorepixel, XtRString, "green"},
  68.     {"maxvelocity", "MaxVelocity", XtRFloat, sizeof(float),
  69.      (Cardinal)&maxv, XtRString, "3.0"},
  70.     {"maxrockspeed", "MaxRockSpeed", XtRFloat, sizeof(float),
  71.      (Cardinal)&maxrockspeed, XtRString, "5.0"},
  72.     {"accelerationPercentage", "AccelerationPercentage", XtRFloat,
  73.      sizeof(float), (Cardinal) &accper, XtRString, "0.1"},
  74.     {"shotAcceleration", "ShotAcceleration", XtRFloat,
  75.      sizeof(float), (Cardinal) &shotacc, XtRString, "2.0"},
  76.     {"maxshots", "MaxShots", XtRInt, sizeof(int),
  77.      (Cardinal) &maxshots, XtRImmediate, (caddr_t) 4},
  78.     {"shotduration", "ShotDuration", XtRInt, sizeof(int),
  79.      (Cardinal) &shotduration, XtRImmediate, (caddr_t) 1000},
  80.     {"defaultfore", "DefaultFore", XtRPixel, sizeof(Pixel),
  81.      (Cardinal) &defaultfore, XtRString, "white"},
  82.     {"defaultback", "DefaultBack", XtRPixel, sizeof(Pixel),
  83.      (Cardinal) &defaultback, XtRString, "black"},
  84. };
  85.  
  86.  
  87. static void CvtStringToFloat(args, num_args, fromVal, toVal)
  88. ArgList args;
  89. Cardinal num_args;
  90. XrmValue    *fromVal;
  91. XrmValue    *toVal;
  92. {
  93.     static float  i;
  94.  
  95.     if (sscanf((char *)fromVal->addr, "%f", &i) == 1) {
  96.     toVal->size = sizeof(float);
  97.     toVal->addr = (caddr_t) &i;
  98.     } else {
  99.     toVal->size = 0;
  100.     toVal->addr = NULL;
  101.     }
  102. }
  103.  
  104. static void AddResource(r, p)
  105. char *r;
  106. Pixel *p;
  107. {
  108.     XrmValue value;
  109.     XrmDatabase db = XtDatabase(dpy);
  110.     value.size = sizeof(Pixel);
  111.     value.addr = (caddr_t) p;
  112.     XrmPutResource(&db, r, XtRPixel, &value);
  113. }
  114.  
  115. main(argc, argv)
  116. Cardinal argc;
  117. char **argv;
  118. {
  119.     static Arg args[] = {
  120.     {XtNwidth, NULL},
  121.     {XtNheight, NULL},
  122.     };
  123.     static Arg scoreargs[] = {
  124.     {XtNforeground, NULL},
  125.     };
  126.     Widget pane;
  127.     extern WidgetClass labelwidgetclass;
  128.     srandom(time(0));
  129.     toplevel = XtInitialize(argv[0], "Roids", table, XtNumber(table),
  130.                 &argc, argv);
  131.     dpy = XtDisplay(toplevel);
  132.     XtAddConverter(XtRString, XtRFloat, CvtStringToFloat, NULL, 0);
  133.     XtGetApplicationResources(toplevel, (caddr_t) NULL, 
  134.                   resources, XtNumber(resources),
  135.                   NULL, (Cardinal) 0);
  136.     AddResource("*background", &defaultback);
  137.     if (DisplayCells(dpy, DefaultScreen(dpy)) <= 2) {
  138.     shippixel = defaultfore;
  139.     rockpixel = defaultfore;
  140.     shotpixel = defaultfore;
  141.     scorepixel = defaultfore;
  142.     }
  143.     args[0].value = (XtArgVal) width;
  144.     args[1].value = (XtArgVal) height;
  145.     pane = XtCreateWidget("pane", vPanedWidgetClass, toplevel,
  146.               args, XtNumber(args));
  147.     XtManageChild(pane);
  148.     scoreargs[0].value = (XtArgVal) scorepixel;
  149.     scorewidget = XtCreateWidget("score", labelWidgetClass, pane,
  150.                  scoreargs, XtNumber(scoreargs));
  151.     XtManageChild(scorewidget);
  152.     gamewidget = (RoidsWidget)
  153.     XtCreateWidget("field", roidsWidgetClass, pane, NULL, 0);
  154.     XtManageChild(gamewidget);
  155.     XtRealizeWidget(toplevel);
  156.     XtMainLoop();
  157. }
  158.  
  159.  
  160. Punt(msg)
  161. {
  162.     fprintf(stderr, "%s\n", msg);
  163.     exit(1);
  164. }
  165.